package com.sos.core.game 
{
	import com.sos.core.DataObject;
	/**
	 * ...
	 * @author Francesco Forte
	 */
	public class GameTarget extends DataObject
	{
		
		// -------------------------------------------------------------------------------
		// CONSTANTS
		// -------------------------------------------------------------------------------
		
		protected static const 		JSON_PROPERTY_INPUT_TARGET_TYPE:String		= "type";
		protected static const 		JSON_PROPERTY_INPUT_TARGET_NAME:String		= "paramName";
		protected static const 		JSON_PROPERTY_INPUT_VALID_TARGETS:String	= "targets";
		
		// -------------------------------------------------------------------------------
		// FIELDS
		// -------------------------------------------------------------------------------
		
		protected var _type:String;
		protected var _name:String;
		protected var _validTargets:Vector.<String>;
		
		// -------------------------------------------------------------------------------
		// CONSTRUCTOR
		// -------------------------------------------------------------------------------
		
		public function GameTarget(data:Object = null) 
		{
			super();
			_validTargets = new Vector.<String>;
			
			if (data != null) load(data);
		}
		
		// -------------------------------------------------------------------------------
		// PROPERTIES
		// -------------------------------------------------------------------------------
		
		public function get type():String
		{
			return _type;
		}

		public function set type(value:String):void
		{
			_type = value;
		}
		
		public function get name():String
		{
			return _name;
		}

		public function set name(value:String):void
		{
			_name = value;
		}
		
		public function get validTargets():Vector.<String> 
		{
			return _validTargets;
		}
		
		public function set validTargets(value:Vector.<String>):void 
		{
			_validTargets = value;
		}
		
		// -------------------------------------------------------------------------------
		// PRIVATE METHODS
		// -------------------------------------------------------------------------------
		
		override protected function validate(data:Object):void
		{
			// Validating data
			if (!data.hasOwnProperty(JSON_PROPERTY_INPUT_TARGET_TYPE)) 		throwLoadMissingPropError(JSON_PROPERTY_INPUT_TARGET_TYPE);
			if (!data.hasOwnProperty(JSON_PROPERTY_INPUT_TARGET_NAME)) 		throwLoadMissingPropError(JSON_PROPERTY_INPUT_TARGET_NAME);
			if (!data.hasOwnProperty(JSON_PROPERTY_INPUT_VALID_TARGETS)) 	throwLoadMissingPropError(JSON_PROPERTY_INPUT_VALID_TARGETS);
			
		}
		
		override protected function fill(data:Object):void
		{
			// Load data
			_type 		= data[JSON_PROPERTY_INPUT_TARGET_TYPE];
			_name 		= data[JSON_PROPERTY_INPUT_TARGET_NAME];
			
			var raw_targets:Array = data[JSON_PROPERTY_INPUT_VALID_TARGETS];
			for (var j:int = 0; j < raw_targets.length; j++)
			{
				_validTargets.push(raw_targets[j]);
			}
		}
		
		// -------------------------------------------------------------------------------
		// PUBLIC METHODS
		// -------------------------------------------------------------------------------
		
		
		
	}

}